import '@css/productPage.css'
import { insuranceListApi, searnameApi } from "@utils/api/productPage"
window.addEventListener('DOMContentLoaded', async () => {

    const { rows } = await insuranceListApi()
    renderproductApi(rows)

    document.querySelectorAll(`.btn`).forEach(item =>
        item.addEventListener(`click`, async (e) => {
            const insurancesName = e.target.parentElement.parentElement.firstElementChild.innerHTML
            window.location.href = `detailsPage.html?insurancesName=${insurancesName}`
        })
    )

})


const renderproductApi = (rows) => {
    document.querySelector('.core').innerHTML = rows.map(item => `<div class="phone">
   <p class="name">${item.insurancesName}</p> 
    <img class="portrait" src="${item.insurancePhone}"> 
   <p>互联网版</p>
   <p class="message">${item.insuranceMessage}</p>
   <p class="price">￥${item.insurancesPrice}/起</p>
   <p><button class="btn">了解详情</button></p>
    </div>
    `).join("")

}
